<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style>
        .head {
            padding: 8px 10px;
            background: #090909;
        }

        .content {
            padding: 20px;
            color: #fff;
            text-align: center;
        }

        .sub {
            /* border-left: 1px solid #dcdcdc; */
            padding-left: 15px;
        }

        .more {
            font-size: 14px;
            color: #4f8af7;
            line-height: 40px;
        }

        .more>* {
            vertical-align: middle;
        }

        .head .van-row .van-col .van-field__label {
            width: 60px;
            color: #e6c678;
        }

        .head .van-row .van-col .van-field__control {
            color: #fff;
            border-bottom: 2px solid #e6c678 !important;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .head .van-row .van-col,
        .content .van-row .van-col {
            margin-bottom: 8px;
            text-align: center;
            font-weight: 300;
            color: #e6c678;
            font-size: 14px;
        }

        .content .van-row .van-col .van-field {
            padding: 0;
            background: #fff;
            border: 1px solid #cecece;
            border-radius: 5px;
        }

        .content .van-row .van-col .van-field__control {
            color: #000;
        }

        @keyframes load {
            0% {
                box-shadow: inset 0px 0px 100px 10px rgba(61, 134, 208, 0.6);
            }

            100% {
                box-shadow: inset 0px 0px 20px 10px rgba(61, 134, 208, 0.1);
            }
        }

        .green {
            color: green;
        }

        .red {
            color: red;
        }

        .yellow {
            color: yellow;
        }

        .right-button .van-button {
            margin-left: 5px;
            min-width: 100px;
        }

        .subTitle {
            padding: 5px 20px;
            color: #e6c678;
            font-weight: bold;
            font-size: 18px;
            box-shadow: 0px 1px 5px rgb(230, 198, 120);
            background: #29292a;
        }

        .subTitle .van-row .van-col {
            text-align: center;
        }

        .van-field__body {
            border-bottom: 2px solid #e6c678;
        }

        .inputMsg {
            font-weight: bold;
            width: 60%;
            color: #090909;
            outline: none;
            border: none;
            text-align: center;
        }

        .van-popup {
            background-color: transparent;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="head">
                <!-- <van-col span="2">
                    <van-button size="small" color="linear-gradient(#fffeaa, #c07d39)" type="primary"
                        @click="onClickLeft">返回</van-button>
                </van-col> -->
                <van-col span="8">
                    <van-field v-model="formData.ProductCode" label="产品编号" placeholder="选择产品编号">
                    </van-field>
                </van-col>
                <van-col span="8">
                    <van-field v-model="formData.ProductName" label="产品名称" placeholder="选择产品名称">
                    </van-field>
                </van-col>
                <van-col span="2">
                    <van-button style="float: right" size="small" color="linear-gradient(#fffeaa, #c07d39)"
                        type="primary" @click="search">查询
                    </van-button>
                </van-col>
            </div>

            <div class="subTitle">
                <van-row type="flex" justify="center">
                    <van-col span="3">产品编号</van-col>
                    <van-col span="7">产品名称</van-col>
                    <van-col span="4">标准包装</van-col>
                    <van-col span="4">塑料框尺寸</van-col>
                    <van-col span="4">皮纹</van-col>
                    <van-col span="2">操作</van-col>
                </van-row>
            </div>
            <div class="content" v-if="!checkValue.length">暂无内容</div>
            <div class="content" v-if="checkValue.length">
                <van-row v-for="(item, index) in checkValue" type="flex" justify="center">
                    <van-col span="3">{{item.ProductCode}}</van-col>
                    <van-col span="7">{{item.ProductName}}</van-col>
                    <van-col span="4">
                        <input class="inputMsg" type="text" v-model="item.Qty"></input>
                    </van-col>
                    <van-col span="4">
                        <input class="inputMsg" type="text" v-model="item.BoxSize"></input>
                    </van-col>
                    <van-col span="4">
                        <input class="inputMsg" type="text" v-model="item.LinesType"></input>
                    </van-col>
                    <van-col span="2">
                        <van-button size="small" color="linear-gradient(#fffeaa, #c07d39)" type="primary"
                            @click="submit(item)">保存
                        </van-button>
                    </van-col>
                </van-row>
            </div>

            <van-popup v-model="showLoading">
                <van-loading color="#e6c678" size="40" vertical>加载中，请稍后...</van-loading>
            </van-popup>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    ProductCode: '',
                    ProductName: '',
                },
                checkValue: [],
                showLoading: false
            },
            created: function () {
                var that = this;
                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }
            },
            mounted() {
                APP.keyBoardChange()
            },
            methods: {
                search() {
                    var that = this
                    that.showLoading = true
                    var obj = {
                        ProductName: that.formData.ProductName,
                        ProductCode: that.formData.ProductCode
                    }
                    // console.log('obj', JSON.stringify(obj))
                    APP.ajax('ZS_getProductList', obj, function (res) {
                        // console.log('res', JSON.stringify(res))
                        var checkArr = []
                        if (that.formData.ProductName && that.formData.ProductCode) {
                            res.ds.map((item) => {
                                if (item.ProductName == that.formData.ProductName && item.ProductCode == that.formData.ProductCode) {
                                    checkArr.push(item)
                                    that.showLoading = false
                                }
                            })
                        } else if (that.formData.ProductCode) {
                            res.ds.map((item) => {
                                if (item.ProductCode.indexOf(that.formData.ProductCode) > -1) {
                                    checkArr.push(item)
                                    that.showLoading = false
                                }
                            })
                        } else if (that.formData.ProductName) {
                            res.ds.map((item) => {
                                if (item.ProductName.indexOf(that.formData.ProductName) > -1) {
                                    checkArr.push(item)
                                    that.showLoading = false
                                }
                            })
                        } else {
                            checkArr = []
                            that.showLoading = false
                        }
                        that.checkValue = checkArr
                    })
                },
                submit(item) {
                    var that = this
                    var obj = {
                        ProductID: item.ProductID,
                        ProductCode: item.ProductCode,
                        ChangeNum: item.Qty,
                        Name: window.localStorage.getItem('loginName'),
                        BoxSize: item.BoxSize,
                        ProductName: item.ProductName,
                        LinesType: item.LinesType
                    }
                    APP.ajax('ZS_ChangeBox', obj, function (res) {
                        // console.log('res', JSON.stringify(res))
                        vm.$toast('保存成功！')
                        api.sendEvent({
                            name: 'refreshBrowser',
                            extra: {
                                clearName: api.pageParam.name
                            }
                        })
                        api.closeFrame()
                    })
                }
            }
        })
    };
</script>

</html>